
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <title>
        管理员管理
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <script type="text/javascript" th:src="@{/lib/loading/okLoading.js}"></script>
    <link rel="stylesheet" th:href="@{/css/main.css}" media="all">
</head>
<style>
    .imgs{display: none;}
    .picture{display: none;}
</style>
<body>
<div class="x-body" id="x-body">
    <form class="layui-form" id="u_admin">
        <input type="hidden" name="id" id="u_id" th:value="${u_admin.id}">
        <div class="layui-form-item">

            <label for="u_login_code" class="layui-form-label">
                <span class="x-red">*</span>登录名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="u_login_code" name="login_code" required="" lay-verify="required"
                       autocomplete="off" class="layui-input" value="" th:value="${u_admin.login_code}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>将会成为您唯一的登入名
            </div>
        </div>
        <div class="layui-form-item">
            <label for="u_name" class="layui-form-label">
                <span class="x-red">*</span>姓名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="u_name" name="name" required="" lay-verify="required"
                       autocomplete="off" class="layui-input" value="" th:value="${u_admin.name}">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="u_email" class="layui-form-label">
                <span class="x-red">*</span>邮箱
            </label>
            <div class="layui-input-inline">
                <input type="text" id="u_email" name="email" required="" lay-verify=""
                       autocomplete="off" class="layui-input" value="" th:value="${u_admin.email}">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="u_phone" class="layui-form-label">
                <span class="x-red">*</span>手机
            </label>
            <div class="layui-input-inline">
                <input type="text" id="u_phone" name="phone" required="" lay-verify="phone"
                       autocomplete="off" class="layui-input" value="" th:value="${u_admin.phone}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="role" class="layui-form-label">
                <span class="x-red">*</span>用户组
            </label>
            <div class="layui-input-inline">
                <select id="u_role_id" name="group_id" >
                    <option value="">请选择角色</option>
                    <option  th:selected="${u_admin.role_id==1}"  value="1">超级管理员</option>
                    <option  th:selected="${u_admin.role_id==2}"  value="2" >普通管理员</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="link" class="layui-form-label">
                <span class="x-red">*</span>缩略图
            </label>
            <div class="layui-input-inline">
                <div class="site-demo-upbar">
                    <div class=" layui-upload-button" style="border:#FFFFFF ;">
                        <button type="button" class="layui-btn" id="test1">
                            <i class="layui-icon">&#xe67c;</i>上传图片
                        </button>
                        <input class="layui-upload" type="file" accept="undefined" id="previewImg" name="admin_pic" onchange="upload(this,)">
                    </div>

                </div>
            </div>

            <a href="javascript:;" style="" onclick="unupload()" class="layui-btn " id="cancel"><i class="layui-icon" >ဂ</i>撤销上传</a>
        </div>
        <div class="layui-form-item" t id="imgshow">
            <label  class="layui-form-label" id="pic_tip"  th:text="${u_admin.admin_pic==null?'无文件':'缩略图展示'}">
            </label>
            <img   id="u_pimages"   th:src="@{${u_admin.getAdmin_pic()}}" name="pimages" style="width: 200px;height: 200px;"/>
            <input id="u_admin_pic" th:value="${u_admin.admin_pic}"   name="image" required="" type="hidden"  value="">
        </div>
        <div class="layui-form-item">
            <label for="u_password" class="layui-form-label">
                <span class="x-red">*</span>密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="u_password" name="password" required="" lay-verify="pass"
                       autocomplete="off" class="layui-input" value="" th:value="${u_admin.password}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                6到16个字符
            </div>
        </div>
        <div class="layui-form-item">
            <label for="u_L_repass" class="layui-form-label">
                <span class="x-red">*</span>确认密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="u_L_repass" name="repass" required="" lay-verify="repass"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block" id="u_status">
                <input type="radio" name="status" value="1" title="启用" th:checked="${u_admin.status==1}" checked="checked">
                <div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon layui-anim-scaleSpring"></i>
                    <div>启用</div>
                </div>
                <input type="radio" name="status" value="0" title="禁用" th:checked="${u_admin.status==2}" checked="checked">
                <div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i>
                    <div>禁用</div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="u_L_repass" class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="add" lay-submit="">
                确认修改
            </button>
        </div>
    </form>
</div>
<script th:src="@{/lib/layui/layui.js}" charset="utf-8">
</script>
<script th:src="@{/js/x-layui.js}" charset="utf-8">
</script>
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form()
            ,layer = layui.layer;
        okLoading.close($);
        //自定义验证规则
        form.verify({
          login_code: function(value){
            if(value.length < 5){
              return '昵称至少得5个字符啊';
            }
          }
          ,pass: [/(.+){6,12}$/, '密码必须6到12位']
          ,repass: function(value){
              if($('#u_password').val()!=$('#u_L_repass').val()){
                  return '两次密码不一致';
              }
          }
        });

        //监听提交
        form.on('submit(add)', function(data){
            // var admindate=$("#adminadd").serialize();
            //var data = data.field;
            var id = $('#u_id').val();
            var login_code = $('#u_login_code').val();
            var name = $('#u_name').val();
            var email = $('#u_email').val();
            var phone = $('#u_phone').val();
            var role_id = $('#u_role_id option:selected').val();
            var admin_pic = $('#u_admin_pic').val();
            var password = $('#u_password').val();
            var status = $('[name=status]:checked').val();
            $.ajax({
                type:'post',
                url:"/administrator/editAdmin",
                data:{
                    id:id,
                    login_code:login_code,
                    name:name,
                    email:email,
                    phone:phone,
                    role_id:role_id,
                    admin_pic:admin_pic,
                    password:password,
                    status:status
                },
                datatype:"json",
                success:function (data) {
                    if(data.status==1){
                        layer.msg(data.msg,{icon:1,time:1000});
                        setTimeout(function(){
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        },1000);
                        return false;
                    }else{
                        layer.msg(data.msg,{icon:5,time:2000});return false;
                    }
                }
            })
            return false;
        });


    });
</script>
<script>
    //轮播图上传
    function upload(obj,id)
    {
        var formData = new FormData();
        formData.append('admin_pic', $('#previewImg')[0].files[0]);
        // formData.append('id', id);//将id追加再id中
        layer.msg('图片上传中', {icon: 16});
        $.ajax({
            type:"post",
            processData: false,
            contentType: false,
            url:"/administrator/upload",
            data:formData,
            success:function(data){
                if(data.status==1){
                    //console.log(data.image_name);
                    layer.closeAll('loading');
                    //layer.msg(data.info,{icon:1,time:1000});
                    $("#u_pimages").attr('src',data.data);
                    $("#u_admin_pic").val(data.data);
                    // $(".imgs").show();
                    return false;
                }else{
                    layer.msg(data.msg,{icon:2,time:1000});
                }
            }
        });
    }
</script>
<script>
    //撤销上传图片
    function unupload() {

    var picpath =$('#u_admin_pic').val();
    $.ajax({
        url:'/administrator/deletePic.html',
        type:'post',
        data:{
            picpath:picpath
        },
        success:function (data) {
            if (data=="success"){
                alert("www");
                layer.msg("撤销成功", {icon: 1, time: 1000});
                $('#u_admin_pic').val('');
                $('#u_pimages').hide();
            }else {
                layer.msg("撤销失败",{icon: 1, time: 1000});
            }

        }
    })
    }
</script>
</body>

</html>